/**
 * jims
 */
package com.jims.master.modules.doctor.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.doctor.entity.ClinicOrdersCost;
import com.jims.master.modules.doctor.service.ClinicOrdersCostService;

/**
 * 门诊项目明细Controller
 * @author CTQ
 * @version 2017-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/doctor/clinicOrdersCost")
public class ClinicOrdersCostController extends BaseController {

	@Autowired
	private ClinicOrdersCostService clinicOrdersCostService;
	
	@ModelAttribute
	public ClinicOrdersCost get(@RequestParam(required=false) String id) {
		ClinicOrdersCost entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = clinicOrdersCostService.get(id);
		}
		if (entity == null){
			entity = new ClinicOrdersCost();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(ClinicOrdersCost clinicOrdersCost, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ClinicOrdersCost> page = clinicOrdersCostService.findPage(new Page<ClinicOrdersCost>(request, response), clinicOrdersCost); 
		model.addAttribute("page", page);
		return "modules/doctor/clinicOrdersCostIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(ClinicOrdersCost clinicOrdersCost, Model model) {
		model.addAttribute("clinicOrdersCost", clinicOrdersCost);
		return "modules/doctor/clinicOrdersCostForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(ClinicOrdersCost clinicOrdersCost, Model model) {
	    StringData data=new StringData();
		int i=clinicOrdersCostService.save(clinicOrdersCost);
        if(i>0){
            data.setCode("success");
            data.setData("保存门诊项目明细成功");
        }else{
            data.setCode("error");
            data.setData("保存门诊项目明细失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(ClinicOrdersCost clinicOrdersCost) {
	    StringData data=new StringData();
		int i=clinicOrdersCostService.delete(clinicOrdersCost);
        if(i>0){
            data.setCode("success");
            data.setData("删除门诊项目明细成功");
        }else{
            data.setCode("error");
            data.setData("删除门诊项目明细失败");
        }
		return data;
	}

}